let app = getApp();
Page({
  data: {
    openid: '',
    dataReport: null,
    imageList: [],
    viewImage: [],
  },
  onLoad(options) {
    let that = this;
    wx.getStorage({
      key: 'openid',
      success(res) {
        that.setData({
          openid: res.data
        });
        console.log(options)
        if (options.flag=='sub'){
          that.loadSbuReport(options);
        }else{
          that.loadReport(options);
        }
       
      },
    })
  },
  loadReport(options) {
    console.log(options)
    let that = this,
      urlArror = [];
    app.get('GetGenZong', {
      action: 'getbyid',
      genzongid: options.id
    }).then((res) => {
      console.log(res);
      let listUrl = res.listurl;
      for (let i in listUrl) {
        urlArror.push(listUrl[i].Url);
      }
      that.setData({
        dataReport: res,
        imageList: listUrl,
        viewImage: urlArror
      });
    })
  },
  loadSbuReport(options){
    let that = this,urlArror = [];
    app.get('GetGenZong', {
      action: 'yueLan',
      genzongid: options.id,
      openid: that.data.openid,
    }).then((res) => {     
      let listUrl = res.listurl;      
      for (let i in listUrl) {
        urlArror.push(listUrl[i].Url);
      }
      that.setData({
        dataReport: res,
        imageList: listUrl,
        viewImage: urlArror
      });
    });
  },
  previewImage(e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current,
      urls: this.data.viewImage
    })
  },
})